package gupao.concurrency.threads;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

public class AtomicReferenceSample {

    static class RouteConfigSample{
        AtomicReference<RouteConfig> routeConifg
                = new AtomicReference<>();

        public void refreshConfig(){
            Map<String, RouteDefinition> newConfig = prepareNewConfigs();
            routeConifg.set(new RouteConfig(newConfig));
        }

        Map<String, RouteDefinition> prepareNewConfigs(){
            //新的配置准备逻辑
            return new HashMap<>();
        }
    }

    static class RouteDefinition{
    }

    @Data
    @AllArgsConstructor
    static class RouteConfig{
        private Map<String,RouteDefinition> routes;
    }
}
